package model.inter

import common.Config
import common.Direction
import java.awt.Rectangle

/**
 * 这里表示可以移动的能力
 */
interface Moveable {


    //可以移动的接口必须要要有的几个属性'
     var mCurrentDirection:Direction;
     var speed:Int

     var mIsWillHit: Boolean


    /**
     * 在那个方向上是否发生了碰撞；
     * @return null表示没有发生碰撞；
     * 返回不为空表示在具体某个方向上发生了碰撞的操作；
     */
    fun willHitInBlockView(blockable: Blockable): Boolean {

        //这里我们要做的一个操作就是判断一下是否发生了碰撞的操作；
        var blockViewRect = blockable.getRect()

        var rect = getNextRect(mCurrentDirection)


        val rectTop = rect.y;
        val rectDown = rect.y + rect.height;

        val rectLeft = rect.x;
        val rectRight = rect.x + rect.width;


        val blockRectTop = blockViewRect.y;
        val blockRectDown = blockViewRect.y + blockViewRect.height;
        val blockRectLeft = blockViewRect.x;
        val blockRectRight = blockViewRect.x + blockViewRect.width;

       // println("blockRect:left:$blockRectLeft top:$blockRectTop right:$blockRectRight down:$blockRectRight")
       // println("ViewRect:left:$rectLeft top:$rectTop right:$rectRight down:$rectDown")

        //这里我们要做一个操作就是判断其是否接触到墙壁了；

        //这里表是不发生碰撞；
        var isHit = when {
            rectTop >= blockRectDown -> false
            rectDown <= blockRectTop -> false
            rectLeft >= blockRectRight -> false
            rectRight <= blockRectLeft -> false
            else -> true
        }

        //这里判断一下是否超出了边界；
        if(rectTop < 0 ||
                rectDown>Config.DEFAULT_WINDOW_HEIGHT ||
                rectLeft<0 ||
                rectRight>Config.DEFAULT_WINDOW_WIDTH ){
            isHit=true
        }


        mIsWillHit=isHit;

        if (isHit) {
            //这里我们把碰撞的对象打印出来；
            println("========  $this hit $blockable ")
            println("========  rectTop $rectTop rectTop<0 ${rectTop<0}  ")
            println("========  rectDown $rectDown rectDown>height ${rectDown>Config.DEFAULT_WINDOW_HEIGHT}  ")
            println("========  rectLeft $rectLeft rectLeft<0 ${rectLeft<0}")
            println("========  rectRight $rectRight rectRight>width ${rectRight>Config.DEFAULT_WINDOW_WIDTH}  ")

        }
        return isHit
    }


    fun move(direction: Direction);

    /**
     * 这里表示下一次移动的矩形的位置；
     */
    fun getNextRect(direction: Direction): Rectangle;

    fun notiyHitIndirection(isWillHit: Boolean) {
        //mIsWillHit=isWillHit;
        println("$this isWillHit: $isWillHit")
        mIsWillHit=isWillHit
    }

}